package com.example.flyWeightPattern;

import com.example.flyWeightPattern.factory.ShapeFactory;
import com.example.flyWeightPattern.shape.Circle;

/**
 * 享元模式测试
 * sun 2017-12-18.
 */
public class FlyweightPatternDemo {
    private static final String colors[] = {"RED","GREEN","BLUE","WEiGHT","BLACK"};

    public static void main(String[] args) {
        for(int i=0; i < 20; ++i) {
            Circle circle =  (Circle) ShapeFactory.getCircle(getRandomColor());
            circle.setX(getRandomX());
            circle.setY(getRandomY());
            circle.setRadius(100);
            circle.draw();
        }
    }
    private static String getRandomColor() {
        return colors[(int)(Math.random()*colors.length)];
    }
    private static int getRandomX() {
        return (int)(Math.random()*100 );
    }
    private static int getRandomY() {
        return (int)(Math.random()*100);
    }
}